package com.pml.util;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class IpTimeStamp{
    String ip=null;
    public IpTimeStamp(){

    }
    public IpTimeStamp(String ip){
        this.ip=ip;
    }
    public String getRandomName(){
        StringBuffer stringBuffer=new StringBuffer();
        String[] ips=ip.split("\\.");
        for (int i=0;i<ips.length;i++){
            stringBuffer.append(addZero(ips[i],3));
        }
        stringBuffer.append(getTimeStamp());
        stringBuffer.append(new Random().nextInt(1000));
        return stringBuffer.toString();

    }

    public String addZero(String str,int length){
        StringBuffer stringBuffer=new StringBuffer();
        stringBuffer.append(str);
        while (stringBuffer.length()<length){
            stringBuffer.insert(0,"0");
        }
        return stringBuffer.toString();
    }

    public String getTimeStamp(){
        Date date=new Date();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyyMMddHHmmssSSS");
        return  simpleDateFormat.format(date);
    }

    public static void main(String[] args) {
        System.out.println(new IpTimeStamp("199.32.44.2").getRandomName());
    }
}